package com.swust.exam.service;



import static org.mockito.Matchers.intThat;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.swust.exam.dao.ClassesMapper;
import com.swust.exam.dao.CourseMapper;
import com.swust.exam.dao.TeachersMapper;
import com.swust.exam.pojo.Classes;
import com.swust.exam.pojo.Course;
import com.swust.exam.pojo.Teachers;


@Service
public class ClassesService {
	@Autowired
	private ClassesMapper classesMapper;
	@Autowired
	private CourseMapper courseMapper;
	@Autowired
	private TeachersMapper teachersMapper;
	

	public Classes get(int id) {
		return classesMapper.selectByPrimaryKey(id);
	}
	
	public int delete(int id) {
		return classesMapper.deleteByPrimaryKey(id);
	}
	
	public int insert(Classes classes) {
		return classesMapper.insert(classes);
	}
	
	public int insertCourseIdAndteacherId(Classes classes) {
		Course course = new Course();
		Teachers teachers = new Teachers();
		
		course.setCourseName(classes.getCourseName());
		course.setSemester(classes.getSemester());
		teachers.setTeacherName(classes.getTeacherName());
		teachers.setTeacherNumber(classes.getTeacherNumber());
		
		int courseId = courseMapper.selectBySemesterAndCourseName(course);
		int teacherId = teachersMapper.selectByTeacherNumberAndTeacherName(teachers);
		classes.setCourseId(courseId);
		classes.setTeacherId(teacherId);
		return classesMapper.insert(classes);
	}
	
	public int updateByclassIdAndteacherId(Classes classes) {
		Course course = new Course();
		Teachers teachers = new Teachers();
		
		course.setCourseName(classes.getCourseName());
		course.setSemester(classes.getSemester());
		teachers.setTeacherName(classes.getTeacherName());
		teachers.setTeacherNumber(classes.getTeacherNumber());
		
		int courseId = courseMapper.selectBySemesterAndCourseName(course);
		int teacherId = teachersMapper.selectByTeacherNumberAndTeacherName(teachers);
		classes.setCourseId(courseId);
		classes.setTeacherId(teacherId);
		return classesMapper.updateByPrimaryKey(classes);
	}
	
	public int update(Classes classes) {
		return classesMapper.updateByPrimaryKey(classes);
	}
	
	public List<Classes>classeslist(){
		return classesMapper.classesList();
		
	}
	
	public List<Classes>courselist(){
		return classesMapper.courseList();
		
	}

	public List<Classes> teacherslist() {
		
		return classesMapper.teachersList();
	}

	public List<Classes> GetDetailClasses(){
		return classesMapper.GetDetailClasses();
	}
	
	public List<Classes> GetCourseName(){
		return classesMapper.GetCourseName();
	}

}
